package cn.boltzjf.sql4j;

import java.util.HashMap;

public class Row extends HashMap<Column<?>, Object> {

    private static final long serialVersionUID = 1L;

    public <T> void set(Column<T> column, T value) {
        super.put(column, value);
    }
    
    public <T> void setIfNotNull(Column<T> column, T value) {
        if (value != null) {
            set(column, value);
        }
    }
    
    public <T> void setIfAbsent(Column<T> column, T value) {
        if (!super.containsKey(column)) {
            set(column, value);
        }
    }
    
    public <T> void setIfAbsentAndNotNull(Column<T> column, T value) {
        if (value != null) {
            setIfAbsent(column, value);
        }
    }
    
    public <T> T get(Column<T> column) {
        return column.javaType().cast(super.get(column));
    }
    
    public boolean containsColumn(Column<?> column) {
        return super.containsKey(column);
    }
    
    public void copy(Row newRow) {
        if (newRow != null) {
            super.putAll(newRow);
        }
    }
}
